﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Microsoft.Phone.Controls;
using OnlineVideos.Utilities;
using Common.Library;
using OnlineVideos.View_Models;
using OnlineVideos.Entities;
using OnlineVideos.Data;
using OnlineVideos;
using Common.Utilities;

namespace OnlineVideos
{
    public partial class WeaponsDescription : PhoneApplicationPage
    {
        List<VideoGameProperties> GameWeapon = null;
        public WeaponsDescription()
        {
            InitializeComponent();
            GameWeapon = new List<VideoGameProperties>();
            Loaded += new RoutedEventHandler(WeaponsDescription_Loaded);
        }

        void WeaponsDescription_Loaded(object sender, RoutedEventArgs e)
        {
            LoadAds();
            string id = "";
            string wid = "";
            string type = "";
            if (NavigationContext.QueryString.TryGetValue("wid", out wid))
            {
                if (NavigationContext.QueryString.TryGetValue("type", out type))
                { }
                if (NavigationContext.QueryString.TryGetValue("id", out id))

                    LayoutRoot.Background = ShowDetail.LoadShowPivotBackground(Convert.ToInt32(id));
                GameWeapon = LoadWeapondes(wid,id,type);
                if (GameWeapon.Count > 0)
                {
                    tblkWeapon.Visibility = Visibility.Collapsed;
                   
                }
                else
                {
                    tblkWeapon.Visibility = Visibility.Visible;
                }
            }
        }

        private List<VideoGameProperties> LoadWeapondes(string wid, string id, string type)
        {
            if (type == "Weapon")
            {
                OnlineVideoDataContext context = new OnlineVideoDataContext(Constants.DatabaseConnectionString);
                IQueryable<GameWeapons> CheatCodesList = from k in context.ShowWeapons where k.WeaponID == Convert.ToInt32(wid) & k.ShowID == Convert.ToInt32(id) select k;
                foreach (var item in CheatCodesList)
                {
                    VideoGameProperties objvideoprop = new VideoGameProperties();
                    tblkVideosTitle.Text = item.Name;
                    objvideoprop.WeaponName = item.Name;
                    if (item.Description != string.Empty)
                    {
                        tblkDescription.Text = item.Description;
                        GameWeapon.Add(objvideoprop);
                    }
                }
            }

            else 
            {
                OnlineVideoDataContext context = new OnlineVideoDataContext(Constants.DatabaseConnectionString);
                IQueryable<GameVehicles> CheatCodesList = from k in context.ShowVehicle where k.VehicleID == Convert.ToInt32(wid) & k.ShowID == Convert.ToInt32(id) select k;
                foreach (var item in CheatCodesList)
                {
                    VideoGameProperties objvideoprop = new VideoGameProperties();
                    tblkVideosTitle.Text = item.Name;
                    objvideoprop.VehicleName = item.Name;
                    if (item.Description != string.Empty)
                    {
                        tblkDescription.Text = item.Description;
                        GameWeapon.Add(objvideoprop);
                    }
                }
            }

            return GameWeapon;
        }
        private void LoadAds()
        {
            try
            {
                PageHelper.LoadAdControl(ContentPanel, adstaWeapon);
            }
            catch (Exception ex)
            {
                Exceptions.SaveOrSendExceptions("Exception in LoadAds Method In Help file.", ex);
            }
        }
    }
}